package mygame;

import com.jme3.app.SimpleApplication;
import com.jme3.material.Material;
import com.jme3.math.Vector3f;
import com.jme3.math.Vector2f;
import com.jme3.scene.Geometry;
import com.jme3.scene.shape.Box;
import com.jme3.math.ColorRGBA;
import com.jme3.scene.shape.Line;
import com.jme3.scene.shape.Dome;
import com.jme3.light.DirectionalLight;
import com.jme3.scene.shape.Cylinder;
import com.jme3.scene.shape.*;
import com.jme3.util.BufferUtils;
import com.jme3.scene.Mesh;
import com.jme3.scene.VertexBuffer.Type;
import com.jme3.math.*;
import com.jme3.scene.Spatial;

public class triPrism 
{
    private float zLength, xWidth, yHeight, xPos,yPos,zPos;
   
    public triPrism()
    {
       
    }
    public triPrism(float xWidth,float yHeight,float zLength,float xPos,float yPos,float zPos)
    {
       
        this.xWidth = xWidth;
        this.yHeight = yHeight;
        this.zLength = zLength;
        this.xPos = xPos;
        this.yPos = yPos;
        this.zPos = zPos;
       
    }
   
    public Spatial createTriPrism()
    {
        Mesh m = new Mesh();
        //vertices of triangular prism
        Vector3f [] vertices = new Vector3f[6];
        vertices[0] = new Vector3f(xPos,yPos,zPos);
        vertices[1] = new Vector3f(xPos+xWidth,yPos,zPos);
        vertices[2] = new Vector3f(xPos+(xWidth/2), yPos+yHeight,zPos);
        vertices[3] = new Vector3f(xPos,yPos,zPos-zLength);
        vertices[4] = new Vector3f(xPos+xWidth,yPos,zPos-zLength);
        vertices[5] = new Vector3f(xPos+(xWidth/2), yPos+yHeight, zPos-zLength);
       
        //texture coordinates
        Vector2f[] texCoord = new Vector2f[6];
        texCoord[0] = new Vector2f(0,0);
        texCoord[1] = new Vector2f(1,0);
        texCoord[2] = new Vector2f(0,1);
        texCoord[3] = new Vector2f(1,1);
        texCoord[4] = new Vector2f(0,0);
        texCoord[5] = new Vector2f(1,0);
       
       
        int [] indexes = { 1,2,0, 3,5,4, 0,3,4, 4,1,0, 4,5,2, 2,1,4, 5,3,0, 0,2,5};
       
        m.setBuffer(Type.Position, 3, BufferUtils.createFloatBuffer(vertices));
        m.setBuffer(Type.TexCoord, 2, BufferUtils.createFloatBuffer(texCoord));
        m.setBuffer(Type.Index,    1, BufferUtils.createIntBuffer(indexes));
        m.updateBound();
       
        Spatial triangleMesh = new Geometry("ourmesh",m);
        //Common/MatDefs/Misc/ShowNormals.j3md rainbow colors
       return triangleMesh;
       
    }
   
   
   
}


